package com.document.controll;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.mvc.View;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;
import org.nutz.mvc.view.JspView;
import org.nutz.mvc.view.ViewWrapper;

import com.document.dao.BasicDao;


public class BaseAction {

	@Inject
	protected BasicDao basicDao;
	
	public void setBasicDao(BasicDao basicDao) {
		this.basicDao = basicDao;
	}
	
	@At("/forward")
	public View forward(@Param("url") String url,HttpServletRequest req){
		req.setAttribute("ctx", req.getContextPath());
		if(url != null){
			return new ViewWrapper(new JspView(url),"");
		}
		return null;				
	}
	
	public void write(HttpServletResponse resp,String outputStr){
		try {
			resp.getOutputStream().write(outputStr.getBytes("utf-8"));
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
